package com.ourteam.product.api;

import com.ourteam.frame.web.AbstractSearchModel;
import com.ourteam.product.ui.dao.IProductUIListOptionDAO;
import com.ourteam.product.ui.dao.ProductUIListOptionDAOQueryBean;
import com.ourteam.product.ui.domain.ProductUIListOptionBean;

public class ProductUIListOptionSearchModel extends AbstractSearchModel<ProductUIListOptionDAOQueryBean> {

	private long listId;

	public long getListId() {
		return listId;
	}

	public void setListId(long listId) {
		this.listId = listId;
	}

	@Override
	public String getMappedDAOField(String aProperty) {
		return ProductUIListOptionBean.getMappedDAOField(aProperty);
	}

	@Override
	protected void doBuildQueryBean(ProductUIListOptionDAOQueryBean queryBean) throws Exception {

		ProductUIListOptionDAOQueryBean.Criteria criteria = queryBean.createCriteria();

		if (this.listId != 0) {
			criteria.andListIdEqualTo(listId);
		}

		if (queryBean.getSortProperties().isEmpty()) {
			queryBean.setSortProperty(IProductUIListOptionDAO.SortIndex);
		}

	}

}
